import { ViewNode } from '../viewmodel/viewNode'
import convertxml from '@ohos.convertxml';
import fileio from '@ohos.fileio';

import { dsl_update_event } from '../test/case_jd'

export const UpdateAndScanXml = (url: string): ViewNode =>  {
    return dsl_update_event;
}

export const LoadAndScanXml = (url: string): ViewNode =>  {
    const fileCompletePath = "/data/storage/el1/bundle/com.example.entry/assets/js/MainAbility/test/developer_mode.xml";
    let xmlResult : any;
    try {
        let xmlInstance = new convertxml.ConvertXML();
        let dsl: string = fileio.readTextSync(fileCompletePath);
        dsl = dsl.replace(/\r\n/g, "");
            xmlResult = xmlInstance.convert(dsl, {
            trim: false,
            declarationKey: 'declaration',
            instructionKey: 'instruction',
            attributesKey: 'attributes',
            textKey: 'text',
            cdataKey: 'cdata',
            doctypeKey: 'doctype',
            commentKey: 'comment',
            parentKey: 'parent',
            typeKey: 'type',
            nameKey: 'viewName',
            elementsKey: 'children'
        });
    } catch (e) {}
    return xmlResult;
}